<script>
  function success(msg, fun) {
    $.cxDialog({
      title: '消息提示',
      info: msg,
      closeBtn: false
    });
    setTimeout(function () {
      $.cxDialog.close();
      fun()
    }, 2000);
  }

  function error(msg, fun) {
    $.cxDialog({
      title: '消息提示',
      info: msg,
      closeBtn: false
    });
    setTimeout(function () {
      $.cxDialog.close();
      fun()
    }, 2000);
  }

  function confirm(info, fun, nfun) {
    $.cxDialog({
      title: '消息提示',
      info: info,
      okText: '确认转账',
      noText: '我再想想',
      ok: function () {
        fun()
      },
      no: function () {
        $.cxDialog.close();
      }
    });
  }
</script>
<div id="memberMain">
  <div class="title"><h4>转账管理</h4></div>
  <div class="height18"></div>
  <div id="hqbManager" class="padding">
    <!--活期宝项目-->
    <div class="clearfix borderGray hqbTop">
      <div class="fl total">
        <div class="li">
          <b>电子积分</b>
          <span class="money" id="elecPoint">0.00</span>元
        </div>
      </div>
      <div class="fl total">
        <div class="li">
          <b>消费积分</b>
          <span class="money" id="custPoint">0.00</span>元
        </div>
      </div>
      <div class="fl total">
        <div class="li">
          <b>激活积分</b>
          <span class="money" id="activitPoint">0.00</span>元
        </div>
      </div>
    </div>
    <div class="height18"></div>
    <div class="tapList borderGray clearfix">
      <div class="height5"></div>
      <form autocomplete="off" id="recharge-form">
        <ul class="formUl" id="userBank">
          <li class="">
            <label class="inputName">会员编号</label>
            <input class="inputText cardName" name="userCode"
                   id="userCode"
                   type="text" style="color: rgb(0, 0, 0);">
            <div class="errorMessage" id="errorMessage" style="display: none"></div>
          </li>
          <li class="">
            <label class="inputName">积分类型</label>
            <select name="style" id="style">
              <option value="elec">电子积分</option>
              <option value="cust">消费积分</option>
              <option value="active">激活积分</option>
            </select>
          </li>
          <li class="">
            <label class="inputName">转出积分</label>
            <input class="inputText" maxlength="18" name="money" id="money" type="number"
                   style="color: rgb(0, 0, 0);">
          </li>
          <li class="">
            <label class="inputName">交易密码</label>
            <input class="inputText" maxlength="16" minlength="6" name="payPwd" id="payPwd" type="password"
                   style="color: rgb(0, 0, 0);">
          </li>
        </ul>
        <ul class="formUl">
          <li>
            <input class="inputBut showL inputBtnBig" type="button" value="确认" id="jax">
          </li>
        </ul>
      </form>
      <div class="height18"></div>
    </div>
  </div>
</div>
<script language="javascript">

  function getPoint() {
    $.post('/transaction/getPoint', {}, function (data) {
      if (data.retCode == 1) {
        $('#elecPoint').html(data.data.cpElecPoint);
        $('#custPoint').html(data.data.cpCustPoint);
        $('#activitPoint').html(data.data.cpActivitPoint);
      } else {

      }
    })
  }

  getPoint();

  function transfer() {

    var info = '你正在转账的金额为:' + $("#money").val() + ',是否确认转账?';
    confirm(info, function () {
      $('body').mLoading('show');
      var pointType = 1;
      if ($("#style").val() == "elec")
        pointType = 3;
      else if ($("#style").val() == "active")
        pointType = 2;
      else
        pointType = 1;

      var money = $("#money").val();
      var userCode = $("#userCode").val();
      var payPwd = $.md5($('#payPwd').val());

      $.post('/transaction/transPoint', {
        pointType: pointType,
        transPoint: money,
        userCode: userCode,
        payPwd: payPwd
      }, function (data) {
        if (data.retCode == 1) {
          $('body').mLoading('hide');
          success(data.retMsg, function () {
            location.reload();
          })
        } else {
          $('body').mLoading('hide');
          error(data.retMsg, function () {
          })
        }
      })
    })
  }

  $('#jax').bind('click', transfer);

  $("#userCode").blur(function () {

    $('#errorMessage').css('display', 'none');

    $.post('/user/getUserByCode', {userCode: $('#userCode').val()}, function (result) {

      if (result.retCode == '1') {
        if (result.data.userName) {
          $('#errorMessage').html(result.data.userName);
        } else {
          $('#errorMessage').html(result.data.userPhone);
        }
        $('#errorMessage').css('display', '');
      }
    })
  });
</script>
